package com.hzhr.iot.collect.service.helper;

import com.hzhr.iot.collect.Global;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceModel;
import com.hzhr.iot.device.sdk.service.Device_CollectDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Device_CollectDeviceServiceHelper {
    @Autowired
    Device_CollectDeviceService device_collectDeviceService;
    @Autowired
    Global global;

    public CollectDeviceModel getByIotDeviceId(Integer iotDeviceId) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_show", "one");
        query.put("_show_info", true);
        query.put("_equal_iotDeviceId", iotDeviceId);
        CollectDeviceModel collectDeviceModel = device_collectDeviceService.get(global.initGlobalHeader(), query).getModel();
        return collectDeviceModel;
    }

    public Integer getIdByIotDeviceIdAndCode(Integer iotDeviceId, String code) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_show", "one");
        query.put("_equal_iotDeviceId", iotDeviceId);
        query.put("_equal_code", code);
        CollectDeviceModel collectDeviceModel = device_collectDeviceService.get(global.initGlobalHeader(), query).getModel();
        if (collectDeviceModel == null) return null;
        return collectDeviceModel.getId();
    }

    public CollectDeviceModel getByIotDeviceIdAndCode(Integer iotDeviceId, String code) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_show", "one");
        query.put("_show_info", true);
        query.put("_equal_iotDeviceId", iotDeviceId);
        query.put("_equal_code", code);
        CollectDeviceModel collectDeviceModel = device_collectDeviceService.get(global.initGlobalHeader(), query).getModel();
        return collectDeviceModel;
    }
}
